/**
 * 
 */
package steffens.java.gui.defaultui.interactive.buttons.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Steffen Baumann
 * @version 1.0 
 *
 */
public class ReflectionMethodCaller {
	void callMethod(String methodName, Object... parameters){
		Class<?>[] parameterClasses ;
		if(parameters == null){
			parameterClasses = new Class<?>[0];
		}else{
			parameterClasses = new Class<?>[parameters.length];
		}
		
		for(int i = 0; i < parameterClasses.length; i++){
			parameterClasses[i] = parameters[i].getClass();
		}
			try {
				Method m = this.getClass().getDeclaredMethod(methodName, parameterClasses);
				m.invoke(this, parameters);
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
